const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
    entry: [
        './src/main.js',
        "core-js/modules/es6.promise",
        "core-js/modules/es6.array.iterator",
    ], //入口文件(要构建的文件)
    output: {
        filename: 'bundle.js', //构建输出文件名
        path: path.resolve(__dirname, 'dist') //构建输出文件夹
    },
    devServer: {  //web-dev-server配置
        open: true,
        port: 3000,
        // contentBase: path.join(__dirname, "dist"),
        hot: true,
        proxy: {
            '/api': {
                target: 'http://vue.studyit.io',
                changeOrigin: true,
            }
        }
    },
    plugins: [
        new htmlWebpackPlugin({ //自动追加 <script type="text/javascript" src="bundle.js"></script></body>到页面最后
            template: path.join(__dirname, './src/index.html'),//指定模板页面,
            filename: "index.html",//生成的页面名称
            title: "vue"
        }),
        new CleanWebpackPlugin(), //打包前清理dist目录
        new VueLoaderPlugin(), //vue文件插件
    ],
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.scss$/,
                use: [
                    'style-loader',
                    'css-loader',
                    'sass-loader',
                ]
            },
            {
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    'file-loader'
                ]
            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: [
                    'file-loader'
                ]
            },
            {
                test: /\.vue$/,
                use: [
                    'vue-loader'
                ]
            },
            {
                test: /\.(js)$/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env'],
                        plugins: [require('@babel/plugin-proposal-class-properties')]
                    }
                },
                exclude: "/node_modules", //排除node_modules
            }
        ]
    },
    resolve: {
        //修改vue导入时的路径
        alias: {
            vue$:"vue/dist/vue.js"
        }
    }
};